package com.newcapec.news.servlet;

import com.newcapec.news.dao.SysUserDao;
import com.newcapec.news.dao.impl.SysUserDaoImpl;
import com.newcapec.news.entity.Page;
import com.newcapec.news.entity.SysUser;
import com.newcapec.news.service.SysUserService;
import com.newcapec.news.service.SysUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description: 登录页面的展示
 * @Author: fujun
 * @Date : 2022/3/16 16:08
 * @Version : 1.0
 * @company 新开普电子股份有限公司
 */
public class ShowAccountHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            req.setCharacterEncoding("utf-8");
//            resp.setCharacterEncoding("utf-8");


        Page page=new Page();
        SysUserService sysUserService=new SysUserServiceImpl();
        //设置总条数到page类中
        page.setTotal(sysUserService.getAllCont());

       //获取用户传递过来的参数
        String pageNum=req.getParameter("pageNum");

       if(pageNum!=null){
           page.setPageNum(Integer.parseInt(pageNum));
       }else{
            page.setPageNum(1);
       }
        page.setPageSize(1);




      List<SysUser> sysUsers= sysUserService.queryAll(page.getOffset(),page.getPageSize(),null);



        req.setAttribute("page",page);
        req.setAttribute("list",sysUsers);
        req.getRequestDispatcher("../WEB-INF/page/AccountManagement.jsp").forward(req,resp);




    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
